package com.waitingresult.number;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @Author: WangShuai
 * @CreateTime: 2022-11-22  18:38
 * @Description:
 * @Version: 1.0
 */
public class BigDecimalDemo {
    public static void main(String[] args) {
        //.setScale(6, RoundingMode.HALF_UP)
        // 记录字符上一次出现的位置
        //methdo1();
        BigDecimal a = new BigDecimal("10.000012001");
        BigDecimal b = new BigDecimal("10.00001200100");
       // System.err.println(a.longValue()); // 10
        //System.err.println(b.longValue()); // 10
        System.out.println(a.setScale(9,RoundingMode.UP));
        System.out.println(b = b.setScale(9,RoundingMode.UP));
        System.out.println("===");
         a = new BigDecimal("10.000");
         b = new BigDecimal("10.000");
         a = a.setScale(3,RoundingMode.UP);
        System.out.println(a);
        System.out.println(b.setScale(3,RoundingMode.UP));

    }

    private static void methdo1() {
        BigDecimal bigDecimal = new BigDecimal(0E-18);
        bigDecimal = bigDecimal.compareTo(BigDecimal.ZERO) > 0 ? BigDecimal.valueOf(1) : BigDecimal.valueOf(0);
        System.out.println(bigDecimal);
        System.out.println(bigDecimal.setScale(6, RoundingMode.HALF_UP));
    }
}
